#include <memory>

#include <unistd.h>

#include "log.hpp"
Log log;

#include "udp_server.hpp"
#include "tcp_server.hpp"
#include "task.hpp"

void* alarm_handler(void* args)
{
    constexpr uint16_t port = 8082;

    std::unique_ptr<UDP_server> alarm_server(new UDP_server);
    alarm_server->init(port);
    alarm_server->run(alarm_task);
}

void* feedback_handler(void* args)
{
    constexpr uint16_t port = 8083;

    std::unique_ptr<TCP_server> feedback_server(new TCP_server);
    feedback_server->init(port);
    feedback_server->run(feedback_task);
}

int main()
{
#ifdef __RELEASE__
    log.change_method(Class);
    daemon(1, 0);
#endif

    // 从单片机中获取报警信息
    pthread_t alarm_thread;
    pthread_create(&alarm_thread, nullptr, alarm_handler, nullptr);

    // 远端从服务器获取最近10条信息
    pthread_t feedback_thread;
    pthread_create(&feedback_thread, nullptr, feedback_handler, nullptr);

    pthread_join(alarm_thread, nullptr);
    pthread_join(feedback_thread, nullptr);

    return 0;
}
